package com.qingmi.farmer.viewmodel;

import android.databinding.ObservableField;

import com.qingmi.farmer.data.DataSetting;
import com.qingmi.farmer.data.model.Delivery;
import com.qingmi.farmer.data.model.GrainDemand;
import com.wjjun.basemvpvm.viewmodel.BaseViewModel;

/**
 * 收购详情header
 * Created by 67535 on 2018/5/1.
 */
public class GrainDemandHeaderViewModel extends BaseViewModel {

    public String grainDemandId;

    public String trolleyId;

    public String grainType;

    public String levelId;

    //收购商名字
    public final ObservableField<String> buyerName = new ObservableField<>();

    //图标
    public final ObservableField<String> icon = new ObservableField<>();

    //品种
    public final ObservableField<String> variety = new ObservableField<>();

    //等级
    public final ObservableField<String> level = new ObservableField<>();

    //单价
    public final ObservableField<Double> dropInPrice = new ObservableField<>(-1.0);

    public final ObservableField<Double> selfPrice = new ObservableField<>(-1.0);

    //需求量
    public final ObservableField<Integer> demanded = new ObservableField<>();

    public final ObservableField<String> timeFormat = new ObservableField<>("yyyy-MM-dd");

    //开始时间
    public final ObservableField<Long> startTime = new ObservableField<>();

    //截至时间
    public final ObservableField<Long> endTime = new ObservableField<>();

    public GrainDemandHeaderViewModel() {

    }

    public void bindGrainDemand(GrainDemand grainDemand) {
        grainDemandId = grainDemand.getId();

        if (grainDemand.getBuyer() != null) {
            buyerName.set(grainDemand.getBuyer().getBuyerName());
        }

        if (grainDemand.getGrain() != null) {
            icon.set(grainDemand.getGrain().getIcon());
            variety.set(grainDemand.getGrain().getGrainTypeName());
            level.set(grainDemand.getGrain().getLevelName());
        }
        demanded.set(grainDemand.getDemandNum());
        startTime.set(grainDemand.getBeginAt());
        endTime.set(grainDemand.getEndAt());

        if (grainDemand.getDeliveries() != null && !grainDemand.getDeliveries().isEmpty()) {
            for (Delivery item : grainDemand.getDeliveries()) {
                if (DataSetting.DELIVERY_TYPE_SELF == item.getId()) {   //自运价
                    selfPrice.set(item.getPrice());
                } else if (DataSetting.DELIVERY_TYPE_DROP_IN == item.getId()) {//上门价
                    dropInPrice.set(item.getPrice());
                }
            }
        }
    }

}
